package Z.dailyExercise._0225;

import java.util.ArrayList;
import java.util.Arrays;

public class _剑指Offer57II和为s的连续正数序列 {
    /**
     * 借助滑动窗口
     * @param target
     * @return
     */
    public int[][] findContinuousSequence(int target) {

        ArrayList<int[]> list = new ArrayList<>();

        int left = 1, right = 2;
        int sum = 1;

        while (left <= target/2){
            if (sum <target){
                sum += right;
                right++;
            }
            if ( sum > target){
                sum -= left;
                left++;
            }

            if ( sum == target){
                int[] num = new int[right-left];
                int start = left;
                int count =0;
                while (count != right-left){
                    num[count++]= start;
                    start++;
                }
                list.add(num);

                //记得还有后面
                sum -= left;
                left = left+2;

            }
        }

        return list.toArray(new int[list.size()][]);
    }
}
